$(function () {

    var accountIsManager = sessionStorage.getItem('accountIsManager'),
        accountSelectManager = sessionStorage.getItem('accountSelectManager'),
        accountName = sessionStorage.getItem('accountName'),
        accountPassword = sessionStorage.getItem('accountPassword'),

        $manager_page_btn = $('#manager-page-btn'),
        $user_page_btn = $('#user-page-btn'),

        $bookManagePage = $('#bookManage'),
        $userManagePage = $('#userManage'),
        $user_title = $('#user-title'),
        $manager_title = $('#manager-title');


    //管理员个人主页显示转换页面的按钮
    if(accountIsManager === '1'){
        $('#page-choice').show();
    }

    //管理员可以切换页面显示情况
    if(accountIsManager === '1' && accountSelectManager === '0'){
        // 选择页面的按钮显示
        $('#page-choice').show();
        $user_page_btn.addClass('gray');
    }else if(accountIsManager === '1' && accountSelectManager === '1'){
        // 选择页面的按钮显示
        $('#page-choice').show();
        $manager_page_btn.addClass('gray');
    }

    //绑定按钮的功能
    $manager_page_btn.on('click',function () {
        console.log('管理员登录');
        $manager_title.show();
        $user_title.hide();
        //显示侧边栏导航的图书和用户管理
        $bookManagePage.show();
        $userManagePage.show();
        //按钮样式变化
        $user_page_btn.removeClass('gray');
        $manager_page_btn.addClass('gray');
    });
    $user_page_btn.on('click',function () {
        console.log('用户登录');
        $user_title.show();
        $manager_title.hide();
        //隐藏侧边栏导航的图书和用户管理
        $bookManagePage.hide();
        $userManagePage.hide();
        //按钮样式变化
        $user_page_btn.addClass('gray');
        $manager_page_btn.removeClass('gray');
    })





    console.log('进入我的');
    var $self_page_items = $('.self-page-item'),
        $top_links = $('.top-link'),

        $current_borrow_link = $('#current-borrow-link'),
        $reservation_link = $('#reservation-link'),
        $debt_link = $('#debt-link'),
        $selfInfo_link = $('#selfInfo-link'),
        $history_borrow_link = $('#history-borrow-link'),

        $current_borrow_page = $('#currentBorrow'),
        $reservation_page = $('#reservation'),
        $debt_page = $('#debt'),
        $accountInfo_page = $('#accountInfo'),
        $history_borrow_page = $('#historyBorrow'),

        $item_input = $('.item-input'),
        $item_radio = $('.item-radio');

    //绑定顶部导航与页面
    $current_borrow_link.on('click',function (){
        $top_links.removeClass('checked');
        $(this).addClass('checked');
        $self_page_items.hide();
        $current_borrow_page.show()
    });
    $reservation_link.on('click',function (){
        $top_links.removeClass('checked');
        $(this).addClass('checked');
        $self_page_items.hide();
        $reservation_page.show()
    });
    $debt_link.on('click',function (){
        $top_links.removeClass('checked');
        $(this).addClass('checked');
        $self_page_items.hide();
        $debt_page.show()
    });
    $selfInfo_link.on('click',function (){
        $top_links.removeClass('checked');
        $(this).addClass('checked');
        $self_page_items.hide();
        $accountInfo_page.show()
    });
    $history_borrow_link.on('click',function (){
        $top_links.removeClass('checked');
        $(this).addClass('checked');
        $self_page_items.hide();
        $history_borrow_page.show()
    });

    //点击编辑个人信息则出现提交按钮
    $('#edit-self-info').on('click',function () {
        $(this).addClass('gray');
        $('#submit-edit-btn').show();
        $('#cancel-edit-btn').show();
        $item_input.removeAttr('readonly');
        $item_input.addClass('edit');
        $item_radio.removeAttr('disabled');
        $item_radio.addClass('edit');
    });
    //点击提交按钮更新账户信息
    $('#submit-edit-btn').on('click',function () {
        //TODO:数据库中更新用户信息
        $('#cancel-edit-btn').hide();
        $(this).hide();
        $item_input.attr('readonly','readonly');
        $item_input.removeClass('edit');
        $item_radio.attr('disabled','disabled');
        $item_radio.removeClass('edit');
        confirm('修改成功！');
        $('#edit-self-info').removeClass('gray');
        $(this).preventDefault();
    });
    //取消编辑个人信息
    $('#cancel-edit-btn').on('click',function (){
        $('#submit-edit-btn').hide();
        $(this).hide();
        $item_input.attr('readonly','readonly');
        $item_input.removeClass('edit');
        $item_radio.attr('disabled','disabled');
        $item_radio.removeClass('edit');
        $('#edit-self-info').removeClass('gray');
    });


    //点击我的借阅
    $('#myBook-btn').on('click',function () {
        $top_links.removeClass('checked');
        $current_borrow_link.addClass('checked');
        $self_page_items.hide();
        $current_borrow_page.show()
    })

    //在form表单中显示个人信息
    $('#username-input').val(accountName);
    $('#password-input').val(accountPassword);
    if(accountIsManager === '0'){
        $('#manager-radio').attr('checked',false);
        $('#user-radio').attr('checked',true);
    }else{
        $('#manager-radio').attr('checked',true);
        $('#user-radio').attr('checked',false);
    }


    $('.action-btn').on('click',function (){
        $(this).parent().parent().children().eq(5).text("2023.2.1");
    });
    $("#jiaofei").click(function(){
        if(window.confirm("缴费成功"))
        {
            $(this).parent().parent().remove();
        }
    });
    $("#jiaofei2").click(function(){
        if(window.confirm("缴费成功"))
        {
            $(this).parent().parent().remove();
        }
    });
    $("#delete1").click(function(){
        if(window.confirm("删除成功"))
        {
            $(this).parent().parent().remove();
        }
    });
    $("#delete2").click(function(){
        if(window.confirm("删除成功"))
        {
            $(this).parent().parent().remove();
        }
    });
    $("#delete3").click(function(){
        if(window.confirm("删除成功"))
        {
            $(this).parent().parent().remove();
        }
    });



})